package com.example.springbootmybatiszuoye.service.impl;

import com.example.springbootmybatiszuoye.mapper.EmpMapper;
import com.example.springbootmybatiszuoye.pojo.Emp;
import com.example.springbootmybatiszuoye.service.EmpService;
import com.example.springbootmybatiszuoye.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

@Component
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;

    /**
     * 新增员工
     * @param emp
     */
    @Override
    public void insertEmp(Emp emp) {
        emp.setCreateTime(LocalDateTime.now());
        emp.setUpdateTime(LocalDateTime.now());
         empMapper.insertEmp(emp);

    }

    /**
     * 根据id删除员工
     * @param id
     */
    @Override
    public void deleteById(String id) {
       empMapper.deleteById(id);
    }

    /**
     * 根据id更新员工
     * @param emp
     */
    @Override
    public void updateById(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.updateById(emp);
    }

    /**
     * 查看所有员工信息
     * @return
     */
    @Override
    public List<Emp> selectEmp() {
      return   empMapper.selectEmp();

    }

    /**
     * 根据id查看员工
     * @param id
     * @return
     */
    @Override
    public Emp selectById(String id) {
      Emp emp = empMapper.selectById(id);
      return emp;
    }
}
